#include <iostream>

#define SHIFT_OFFSET 5

// cesear简化实现
// 0x20 space
// 0x5F (0x7F - 0x20)

std::string encode(const char* p, int len)
{
	std::string s = "";
	char ch;
	while (*p)
	{
		ch = (*p + SHIFT_OFFSET - 0x20) % 0x5F + 0x20;
		s += ch;
		p++;
	}

	return s;
}

std::string decode(const char* p, int len)
{
	std::string s = "";
	char ch;
	while (*p)
	{
		ch = (*p - SHIFT_OFFSET - 0x20 + 0x5F) % 0x5F + 0x20;
		s += ch;
		p++;
	}

	return s;
}


int main()
{
	std::string input = "TP xyz(900)~001";
	std::string es = encode(input.c_str(), input.size());

	std::string ds = decode(es.c_str(), es.size());

	std::cout << "INPUT:  " << input << std::endl;
	std::cout << "ENCODE: " << es << std::endl;
	std::cout << "DECODE: " << ds << std::endl;

	return 0;
}
